local skel = fk.CreateSkill {
  name = "emo__yugee",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__yugee"] = "鱼歌",
  [":emo__yugee"] = "锁定技，每当你使用一张锦囊牌时，你随机获得一个非坐骑装备技能，当你发动以此法获得的装备技能后，你失去之并摸两张牌。",
  ["@[:]emo__yugee"] = "鱼歌",

  ["$emo__yugee1"] = "（歌声）",
}

---@param room Room
local getYugeeSkills = function (room)
  local skills = room:getTag("emo__yugee_skills")
  if skills == nil then
    skills = {}
    for name, card in pairs(Fk.all_card_types) do
      ---@cast card EquipCard
      if card.package and not table.contains(room.disabled_packs, card.package.name) and not card.is_derived and card.equip_skill then
        if table.contains({Card.SubtypeTreasure, Card.SubtypeWeapon, Card.SubtypeArmor}, card.sub_type) then
          table.insertIfNeed(skills, card.equip_skill.name)
        end
      end
    end
    room:setTag("emo__yugee_skills", skills)
  end
  return skills
end

skel:addEffect(fk.CardUsing, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return data.card.type == Card.TypeTrick
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = table.filter(getYugeeSkills(room), function(s)
      return not player:hasSkill(s, true)
    end)
    if #skills > 0 then
      local skill = table.random(skills)
      room:addTableMark(player, "@[:]emo__yugee", skill)
      room:handleAddLoseSkills(player, skill, skel.name, false)
    end
  end,
})

skel:addEffect(fk.AfterSkillEffect, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return data.skill and table.contains(player:getTableMark("@[:]emo__yugee"), (data.skill:getSkeleton() or data.skill).name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skill = (data.skill:getSkeleton() or data.skill).name
    room:removeTableMark(player, "@[:]emo__yugee", skill)
    room:handleAddLoseSkills(player, "-"..skill, skel.name, false)
    player:drawCards(2, skel.name)
  end,
})

return skel
